<html>
<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" %>
<%@include file="/quick/include/common.jsp"%>
<%@include file="/quick/include/globalScope.jsp"%>
  <head>
    <title>学生评教</title>
  </head>

    <c:if test="${not empty message}">
      <div  align="left" id="title" style="height:40px;vertical-align:bottom;bgcolor:blue;"><br><h3><STRONG><c:out value='${message}'/></STRONG></h3></div>
    </c:if>
    
<div id='question_div' ></div>
<div id='course_div' ></div>
<script>
  var evtJson=<c:out value='${model.evtJson}' escapeXml='false'/>;
  var standardJson=<c:out value='${model.standardJson}' escapeXml='false'/>;
  var itemJson=<c:out value='${model.itemJson}' escapeXml='false'/>;
  var questionJson=<c:out value='${model.questionJson}' escapeXml='false'/>;
  var evtStore=new Ext.data.SimpleStore({
    'fields':['id','courseTeacher','isFinish','courseName','teacherName'],
    data:evtJson
  });
  var itemStore=new Ext.data.SimpleStore({
    'fields':['itemCode','itemName'],
    data:itemJson
  });
  var questionStore=new Ext.data.SimpleStore({
    'fields':['itemName','questionCode','questionName'],
    data:questionJson
  });

 	var comboStore=new Ext.data.SimpleStore({
      'fields':['code','name'],
      data:standardJson
    });
  
var currentRec;
var submitForm;
var questionCombo;
Ext.onReady(function(){
	form=new Ext.form.FormPanel(
	  {
	  		labelAlign:'right',
		    frame:true,
		    border:true,
		    el:'course_div',
		    height:40,
		    items:[{
		      layout:'column',
		      items:[
		        {
				    layout:'form',
				    columWidth:2/3,
				    items:[
					    {
			            xtype:'combo',   
			            fieldLabel:'评教课程',
			            typeAhead:true, 
			            store: evtStore,   	
			            editable: false,  
			            mode: 'local',   
			            hiddenName:'COURSE_ID',   
			            id:'_COURSE_ID',   
			            displayField:'courseTeacher',
			            valueField:'id',
			            triggerAction: 'all', 
			            width:300,
			            emptyText:'请选择'
					 }
				    ]
		        },{
		                layout:'form',
		                columnWidth:1/3,
		                items:[
				         {
				            xtype:'button',   
				            text:'确定'   ,
				            handler:evaluation   
				         }
	                    ]	        
		        }
		      ]
		    }]
	  }
	);
	form.render();

  var panel=new Ext.Panel({
    layout:'border',
    el:'question_div',
    height:700,
    autoScroll:true,
    items:[{
      title:'评教课程/教师',
      region:'north',
      height:65,
      items:[form]
    },{
      region:'center',
      title:'评教内容',
      id:'c_question_div',
      width:800,
      items:[{id:'c_question_form',hidden:true}]
    }]
  });
  panel.render();


    questionCombo=form.getForm().findField('_COURSE_ID');
    questionCombo.on('select',function(c,r,i){
      currentRec=r;
      if(Ext.isIE6){evaluation()}
    });
});

  function evaluation(){
    if(currentRec==null) return;
    var combo=form.getForm().findField('_COURSE_ID');
    var cid=combo.getValue();
    var finish=currentRec.get('isFinish');
    if(finish=='Y'){
      var cname=currentRec.get('courseTeacher');
      alert(cname+',请选择未评课程评教！');
      return;
    }
    questionForm(cid);
  }
  
  
  function questionForm(cid){
     function _initColumns() {
    	var cn=3
		var _columns = [];
		for (var j = 0; j < cn; j++) {
			var c = {
				columnWidth : 1 / cn,
				layout : 'form',
				items :[]
			};
			_columns.push(c);
		}
		return _columns;
	}
	
	var rows=[{id:'refid',xtype:'hidden',value:cid}];
	var r=currentRec;
	var cname=r.get('courseName');
	var tname=r.get('teacherName');
	rows.push({
	  xtype:'label',
	  height:330,
	  html:'<br>&nbsp;&nbsp;&nbsp;&nbsp;<b>课程名称：</b>'+cname+'&nbsp;&nbsp;&nbsp;&nbsp;'+'<b>任课教师：</b>'+tname+'<br><br>'
	});	
	    var ti=10000;
	  itemStore.each(function(item){
	    var itemName=item.get('itemName');
	    questionStore.filter('itemName',itemName);
	    var itemColumns=_initColumns();
	    var n1=0;
	    questionStore.each(function(question){
	      var name=question.get('itemName');
	      var questionCode=question.get('questionCode');
	      var questionName=question.get('questionName');
	      var questionCombo={
	        xtype:'combo',
	        allowBlank:false,
	        fieldLabel:questionName+"<font color=red>*</font>",
	        editable: false,  
            mode: 'local',
	        store:comboStore,
	        id:'_'+questionCode,
            displayField:'name',
            valueField:'code',
            hiddenName:questionCode,
            triggerAction: 'all', 
            width:100,
            emptyText:'请选择',
            tabIndex:ti++
	      }
	      var n2=n1%3;
	      n1++;
	      itemColumns[n2].items.push(questionCombo);
	    });
	    Ext.each(itemColumns,function(ic){
	      if(ic.items.length==0) ic.items.push({hidden:true});
	    });
	    rows.push({
				xtype : 'fieldset',
				cls:'x-fieldset',
				autoHeight : true,
				collapsible : true,
				layout:'column',
				title : itemName,
				items : itemColumns
		});
	  });	

    
    
    rows.push({
				xtype : 'fieldset',
				cls:'x-fieldset',
				autoHeight : true,
				collapsible : true,
      title:'对教学的意见和建议',
      items:[{
	      xtype:'textarea',
	      allowBlank:false,
	      fieldLabel:'对教学的意见和建议<font color=red>*</font>',
	      tabIndex:11000,
	      id:'NOTE',
	      width:800
	    }]
    });
	
	submitForm=new Ext.form.FormPanel({
	   items:rows,
	   url:g_rootPath+'evaluation/evt/student/studentEvTeaching.html',
	   id:'c_question_form',
	   labelAlign:'left',
	   labelWidth:300,
       frame:false,
       border:false,
       onSubmit: Ext.emptyFn,
       buttons:[{
         text:'提交',
         handler:submitEv
       }]

	});
       var p=Ext.getCmp('c_question_div');
	   p.remove('c_question_form');
	   p.add(submitForm);
	   p.doLayout();	
  }
  
  function submitEv(){
    var valid=globalScope._validForm(submitForm);
    if(valid)    submitForm.getForm().submit({
      success:function(form,action){
        currentRec.set('isFinish','Y');
        var courseTeacher=currentRec.get('courseTeacher');
        currentRec.set('courseTeacher',courseTeacher+'【已评】');
        questionCombo.reset();
        submitForm.getForm().reset();
        submitForm.hide();
        questionCombo.focus();
        Ext.Msg.alert('谢谢','评教成功');
      },
      failure:function(){
        Ext.Msg.alert('错误','评教失败');
      }
    });
  }

/*  
	function questionTable(){
	  var r=currentRec;
	  var cells=[];
	  var r1c1={html:'课程名称：'};
	  var r1c2={html:r.get('courseName')};
	  var r1c3={html:'任课教师：'};
	  var r1c4={html:r.get('teacherName')};
	  cells.push(r1c1);
	  cells.push(r1c2);
	  cells.push(r1c3);
	  cells.push(r1c4);
	  var r2c1={html:'<div align=center>评价项目</div>',colspan:2}
	  var r2c2={html:'<div align=center>评价等级</div>',colspan:2}
	  cells.push(r2c1);
	  cells.push(r2c2);
	  
	  itemStore.each(function(item){
	    var itemName=item.get('itemName');
	    questionStore.filter('itemName',itemName);
	    var c=questionStore.getCount();
	    var rcItem={html:itemName,rowspan:c};
	    cells.push(rcItem);
	    questionStore.each(function(question){
	      var name=question.get('itemName');
	      var questionCode=question.get('questionCode');
	      var questionName=question.get('questionName');
	      var rcQuestionName={html:questionName,colspan:2};
	      var rcQuestion={html:'<select style=\'width:100px\' name='+questionCode+'><option value=A>优</option><option value=B>良</option><option value=C>中</option><option value=D>差</option></select>'}
	      cells.push(rcQuestionName);
	      cells.push(rcQuestion);
	    });
	  });
	  
	  
	  var tab={
        id:'c_question_tab',
        layout:'table',
        defaults:{
          bodyStyle:'padding:1px'
        },
        layoutConfig:{
          columns:4
        },
        width:800,
        items:cells
      }
       var p=Ext.getCmp('c_question_div');
	   p.remove('c_question_tab');
	   p.add(tab);
	   p.doLayout();	
	}   
*/
</script>  
</html>   
